package tech.aistar.day05.this_demo;

/**
 * 本类用来演示: 英雄类
 *
 * @author: success
 * @date: 2021/3/12 2:42 下午
 */
public class Hero {
    private int id;

    private String name;

    private String type;

    public Hero(){
        System.out.println("空参构造");
    }

    public Hero(int id,String name){
        System.out.println("两参构造...");
        this.id = id;
        //this.name = name;

        //可以在构造方法中调用setter方法
        setName(name);
    }

    public Hero(int id,String name,String type){
//        如果存在于构造方法中,那么代表的是调用另外一个带参构造,并且只能出现在构造方法的首行.
//        this.id = id;
//        this.name = name;

        this(id,name);
        this.type=type;
        System.out.println("三参构造...");
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if("猴子".equals(name)){
            this.name = "***";
            return;
        }
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    @Override
    public String toString() {
        return "Hero{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", type='" + type + '\'' +
                '}';
    }
}
